﻿using System.Web.Mvc;
using ShopB2C.Core.Helpers;
using ShopB2C.Core.Resources;

namespace ShopB2C.Core {
    public class BaseController1 : Controller, IBaseController {
        /// <summary>
        /// 在线缩略图预览
        /// </summary>
        /// <param name="w">宽</param>
        /// <param name="h">高</param>
        /// <param name="s">源文件</param>
        /// <returns></returns>
        public ActionResult Thumb(int w = 300, int h = 100, string s = "") {
            w = w <= 1 ? 300 : w;
            h = h <= 1 ? 100 : h;

            if (System.IO.File.Exists(Server.MapPath(s))) {
                Response.ContentType = "image/jpeg";
                System.IO.MemoryStream ms = ThumbImageHelper.CuteThumbPhoto(w, h, Server.MapPath(s), false, true);
                Response.BinaryWrite(ms.ToArray());
            }


            return new EmptyResult();
        }
        /// <summary>
        /// 创建分页匿名对象
        /// </summary>
        /// <param name="HrefFormat">Url 格式字符串，
        /// 注意 UrlHelper 会将 {0} 转义，链接到字符串需要占用格式化字符串 {0} 占位符</param>
        /// <param name="pageSize">总页数</param>
        /// <param name="pageIndex">当前页码</param>
        /// <returns>分页匿名对象</returns>
        protected virtual object CreatePager(string HrefFormat, int totalRows, int pageSize, int pageIndex) {
            return new {
                //PageIndex = pageIndex,
                //TotalRows = totalRows,
                //PageSize = pageSize,


                //FirstPageText = CoreResources.PagerFirst,
                //LastPageText = CoreResources.PagerLast,

                //PageDownText = CoreResources.PagerNext,
                //PageUpText = CoreResources.PagerPrevious,

                //HrefFormat = Server.UrlDecode(HrefFormat)
            };
        }
    }
}